<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<?php $this->load->view('admin/header.html')?>
<script type="text/javascript" src="<?php echo base_url()?>common/js/validateForm.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/js/MyJs.js"></script>
<script type="text/javascript">
    function Success(data) {
        $.Success(data);
    }
    UE.getEditor('contents');
    $(function () {
        $.validate_contents('ajax_form');
    });
    KindEditor.ready(function (K) {
        var editor = K.editor({
            uploadJson: '/common/kindeditor/php/upload_json.php',
            allowFileManager: true
        });
        function initimg() {
            editor.loadPlugin('image', function () {
                editor.plugin.imageDialog({
                    imageUrl: K('#url1').val(),
                    clickFn: function (url, title, width, height, border, align) {
                        K('#imgurl').val(url);
                        K('#img_tag').attr('src', url);
                        editor.hideDialog();
                    }
                });
            });
        }
        K('#img_tag').click(function () {
            initimg();
        });
        K('#imgurl').dblclick(function () {
            initimg();
        });
    });
    function Del(contents_id) {
        layer.confirm("确定删除", function () {
            $.post("/admin/contents/del_contents/" + contents_id, null, function (data) {
                var jsonData = $.parseJSON(data);
                if (jsonData.Statu == 'ok') {
                    Success(jsonData)
                }
                else {
                    Success(jsonData)
                }
            })
        }, function () {
            layer.msg('取消删除', { icon: 0 });
        })
    }

</script>
<div id="dcMain">
    <!-- 当前位置 -->
    <div id="urHere">
        DouPHP 管理中心
        <?php foreach($crumbs_items as $crumbs_item):?>
        <b>></b><a href="<?php echo $crumbs_item[0]?>"><?php echo $crumbs_item[1]?></a>
        <?php endforeach;?>
    </div>
    <div id="manager" class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
        <h3><?php echo end($crumbs_items)[1]?></h3>
        <form id="ajax_form" action="<?php echo site_url('admin/contents/edit_contents')?>" method="post">
            <input id="contents_id" name="contents_id" type="hidden" value="<?php echo !empty($contentsModel)?$contentsModel->contents_id:0?>" />
            <input id="menuid" name="menuid" type="hidden" value="<?php echo !empty($contentsModel)?$contentsModel->menuid:$menuid?>" />
            <input id="mark" name="mark" type="hidden" value="<?php echo !empty($contentsModel)?1:0?>" />
            <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
                <tr>
                    <td width="100" align="right">标题</td>
                    <td>
                        <input type="text" id="title" name="title" size="40" class="inpMain" value="<?php echo !empty($contentsModel)?$contentsModel->title:""?>" />
                    </td>
                </tr>
                <tr>
                    <td width="100" align="right">关键字</td>
                    <td>
                        <textarea id="keyword" name="keyword" style="height:100px;width:665px;resize:none;"><?php echo !empty($contentsModel)?$contentsModel->keyword:""?></textarea>
                    </td>
                </tr>
                <tr>
                    <td width="100" align="right">描述</td>
                    <td>
                        <textarea id="description" name="description" style="height:100px;width:665px;resize:none;"><?php echo !empty($contentsModel)?$contentsModel->description:""?></textarea>
                    </td>
                </tr>
                <tr>
                    <td width="100" align="right">图片</td>
                    <td style="position:relative;">
                        <img id="img_tag" src="<?php echo !empty($contentsModel)?$contentsModel->imgurl:""?>" onerror="this.src='<?php echo base_url('common')?>/images/nopic.png'" style="height:100px;width:100px;cursor:pointer;float:left;" />
                        <div style="float: left;position: absolute;bottom: 9px;left: 113px;">
                            <input type="text" id="imgurl" name="imgurl" size="40" class="inpMain" value="" readonly="readonly" />
                            <a href="javascript:$.DeleteImg('img_tag','imgurl')" style="margin-left:20px;">删除</a>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td width="100" align="right">内容</td>
                    <td>
                        <textarea id="contents" name="contents" style="height:500px;width:965px;"><?php echo !empty($contentsModel)?$contentsModel->contents:""?></textarea>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="submit" class="btn" value="<?php echo !empty($contentsModel)?"修改":"添加"?>" />
                        <?php if(!empty($contentsModel)){?>
                        <input type="button" class="btn" onclick="Del(<?php echo $contentsModel->contents_id?>)" value="删除" />
                        <?php }?>
                        <input type="button" class="btn" value="返回" onclick="GoBack()" />
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>


